<?php
/**
 * Created by PhpStorm.
 * User: 秋刀鱼
 * Date: 2018/7/31
 * Time: 11:35
 */

namespace app\models;

use yii\base\Model;
use Yii;
use \common\helps\tools;//使用工具类

class TypeNum extends Model
{

    //表名
    protected $table = '';

    /**
     * title 添加 专利 论文类型数目
     * @param $project_id
     * @param $type_count
     * @param $type
     * @param $create_time
     * @return int
     * @throws \yii\db\Exception
     */
    public function addNum($project_id,$type_count,$type,$create_time,$type_id)
    {


        $table = 'type_num';
        $id = tools::createUuid();

        $field = ['id','project_id','type_count','type','create_time','type_id'];
        $batchData = [[$id,$project_id,$type_count,$type,$create_time,$type_id]];
        $result = Yii::$app->db->createCommand()->batchInsert($table,$field,$batchData)->execute();





        return $result;
    }

    /**
     * title 类型
     * @param $project_id
     * @return array|bool
     */
    public function selectNum($project_id)
    {
        $query =  new \yii\db\Query();
        $type_num = $query->select(['id', 'type_count', 'type', 'type_id'])->from('data_yii.type_num')->where(['project_id' => $project_id])->all();
        foreach($type_num as $k => $v){
            //论文
            if($v['type'] == 1){
                $thesis = $query->select(['id', 'content'])->from('data_yii.thesis_type')->where(['id' => $v['type_id']])->one();
                $type_num[$k]['content'] = $thesis['content'];
            }else if($v['type'] == 2){
                //专利
                $patent = $query->select(['id', 'content'])->from('data_yii.patent_type')->where(['id' => $v['type_id']])->one();
                $type_num[$k]['content'] = $patent['content'];
            }


        }
        return $type_num;
    }

}